{
 "cells": [
  {
   "cell_type": "raw",
   "id": "4e5d3f3b",
   "metadata": {},
   "source": [
    "·2022/10/11/week8\n",
    "·python课堂笔记"
   ]
  },
  {
   "cell_type": "raw",
   "id": "7eb37b8b",
   "metadata": {},
   "source": [
    "本周内容\n",
    "0.代码的注释\n",
    "1.用户的输入\n",
    "2.格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f56caaa4",
   "metadata": {},
   "source": [
    "## 0.代码的注释\n",
    ">1.#,一般写在代码块的最上边，或者每一行代码的最后，用于代码思路的记录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f79842bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "#Author:zhichao"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4ecafd49",
   "metadata": {},
   "source": [
    ">.\"注释内容”，一般是注释代码块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2920e753",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "三个引号注释代码块内容，不运行\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "import random\n",
    "wait_time=random.randit(1,60)\n",
    "print(wait_time)\n",
    "\n",
    "word=\"bottles\"\n",
    "print(word)\n",
    "'''\n",
    "print('三个引号注释代码块内容，不运行')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "65b03205",
   "metadata": {},
   "source": [
    "# 1.用户输入\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0c181cd1",
   "metadata": {},
   "source": [
    " 1.input()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "72d86ebd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号admin\n",
      "密码123456\n",
      "admin\n",
      "123456\n"
     ]
    }
   ],
   "source": [
    "#登陆系统\n",
    "username=input(\"账号\")\n",
    "password=input(\"密码\")\n",
    "\n",
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "06b46fa7",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Input \u001b[0;32mIn [24]\u001b[0m, in \u001b[0;36m<cell line: 6>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      3\u001b[0m userl\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124madmin\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m      4\u001b[0m passwordl\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m123456\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m----> 6\u001b[0m username\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m账号:\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m      7\u001b[0m password\u001b[38;5;241m=\u001b[39m\u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m密码:\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m      9\u001b[0m \u001b[38;5;66;03m#情景一:输入信息正确，登陆成功\u001b[39;00m\n",
      "File \u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/ipykernel/kernelbase.py:1075\u001b[0m, in \u001b[0;36mKernel.raw_input\u001b[0;34m(self, prompt)\u001b[0m\n\u001b[1;32m   1071\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_allow_stdin:\n\u001b[1;32m   1072\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m StdinNotImplementedError(\n\u001b[1;32m   1073\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mraw_input was called, but this frontend does not support input requests.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m   1074\u001b[0m     )\n\u001b[0;32m-> 1075\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_input_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m   1076\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m   1077\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parent_ident\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m   1078\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_parent\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m   1079\u001b[0m \u001b[43m    \u001b[49m\u001b[43mpassword\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m   1080\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/ipykernel/kernelbase.py:1120\u001b[0m, in \u001b[0;36mKernel._input_request\u001b[0;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[1;32m   1117\u001b[0m             \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[1;32m   1118\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[1;32m   1119\u001b[0m     \u001b[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[0;32m-> 1120\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInterrupted by user\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28mNone\u001b[39m\n\u001b[1;32m   1121\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[1;32m   1122\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlog\u001b[38;5;241m.\u001b[39mwarning(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid Message:\u001b[39m\u001b[38;5;124m\"\u001b[39m, exc_info\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "#登陆系统 迭代1:增加了判断功能\n",
    "#假设我们数据库有用户信息：账号：admin,密码,123456\n",
    "userl=\"admin\"\n",
    "passwordl=\"123456\"\n",
    "\n",
    "username=input(\"账号:\")\n",
    "password=input(\"密码:\")\n",
    "\n",
    "#情景一:输入信息正确，登陆成功\n",
    "if userl==username and passwordl==password:\n",
    "    print(\"欢迎\"+userl+\"登陆!\")\n",
    "#情景二:账号不存在或密码不正确\n",
    "else:\n",
    "    print(\"账号不存在或者密码不正确!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8e6e43a",
   "metadata": {},
   "outputs": [],
   "source": [
    "#登陆系统 迭代2:增加循环功能\n",
    "#假设我们数据库有用户信息：账号：admin,密码,123456\n",
    "userl=\"admin\"\n",
    "passwordl=\"123456\"\n",
    "\n",
    "for i in range(3,0,-1): #i 是一个 int\n",
    "    username=input(\"账号:\")\n",
    "    password=input(\"密码:\")\n",
    "    \n",
    "    #情景一:输入信息正确，登陆成功\n",
    "    if userl==username and passwordl==password:\n",
    "        print(\"欢迎\"+userl+\"登陆!\")\n",
    "        break\n",
    "    #情景二:账号不存在或密码不正确\n",
    "    else:\n",
    "        if i ==1:\n",
    "            print(\"三次输入失败，请1小时后再来尝试\")\n",
    "            else:\n",
    "                print(\"账号不存在或者密码不正确!\")\n",
    "                print(\"您还有\"+str(i)+\"次尝试的机会\")#str强制将int转换成str"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8d7758e4",
   "metadata": {},
   "outputs": [],
   "source": [
    "username"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "850da4c4",
   "metadata": {},
   "source": [
    "# #2.格式化输出\n",
    "1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "41ca7bce",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "cannot assign to operator (1413971414.py, line 8)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  Input \u001b[0;32mIn [30]\u001b[0;36m\u001b[0m\n\u001b[0;31m    info= '''-----INFO OF'''+name='''------'''='''\u001b[0m\n\u001b[0m          ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m cannot assign to operator\n"
     ]
    }
   ],
   "source": [
    "#用户注册系统 方法二：占位符\n",
    "name=input(\"姓名:\")\n",
    "age=input(\"年龄:\")\n",
    "job=input(\"工作:\")\n",
    "salarry=input(\"收入:\")\n",
    "reg=input(\"地区:\")\n",
    "\n",
    "info= '''-----INFO OF'''+name='''------'''='''\n",
    "年龄:'''+age+'''\n",
    "工作:'''+job+'''\n",
    "收入:'''+salary+'''\n",
    "地区:'''+reg\n",
    "\n",
    "print(info)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9a8407b3",
   "metadata": {},
   "outputs": [],
   "source": [
    "#input 作为用户输入，其都以字符串形式返回\n",
    "age=input(\"年龄:\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "7e8dcefe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名:jack\n",
      "年龄:24\n",
      "工作:服务业\n",
      "收入:25000\n",
      "地区:深圳\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'salary' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[0;32mIn [34]\u001b[0m, in \u001b[0;36m<cell line: 8>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      5\u001b[0m salarry\u001b[38;5;241m=\u001b[39m\u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m收入:\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m      6\u001b[0m reg\u001b[38;5;241m=\u001b[39m\u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m地区:\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m      8\u001b[0m info\u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'''\u001b[39m\u001b[38;5;124m-----INFO OF \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m------\u001b[39m\n\u001b[1;32m      9\u001b[0m \u001b[38;5;124m年龄: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\n\u001b[1;32m     10\u001b[0m \u001b[38;5;124m工作: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\n\u001b[1;32m     11\u001b[0m \u001b[38;5;124m收入: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\n\u001b[0;32m---> 12\u001b[0m \u001b[38;5;124m地区: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m'''\u001b[39m\u001b[38;5;241m%\u001b[39m(name,age,job,\u001b[43msalary\u001b[49m,reg)\n\u001b[1;32m     13\u001b[0m \u001b[38;5;28mprint\u001b[39m(info)\n",
      "\u001b[0;31mNameError\u001b[0m: name 'salary' is not defined"
     ]
    }
   ],
   "source": [
    "#用户注册系统 方法二：占位符 %s,依次有序输入\n",
    "name=input(\"姓名:\")\n",
    "age=input(\"年龄:\") # 强制将str 转换成 int\n",
    "job=input(\"工作:\")\n",
    "salarry=input(\"收入:\")\n",
    "reg=input(\"地区:\")\n",
    "\n",
    "info= '''-----INFO OF %s------\n",
    "年龄: %s\n",
    "工作: %s\n",
    "收入: %s\n",
    "地区: %s'''%(name,age,job,salary,reg)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "762bde98",
   "metadata": {},
   "outputs": [],
   "source": [
    "#用户注册系统 方法三：format()格式化输出函数\n",
    "name=input(\"姓名:\")\n",
    "age=input(\"年龄:\") # 强制将str 转换成 int\n",
    "job=input(\"工作:\")\n",
    "salarry=input(\"收入:\")\n",
    "reg=input(\"地区:\")\n",
    "\n",
    "inpo='''------INFO OF{姓名}-----\n",
    "年龄\n",
    "工作\n",
    "收入\n",
    "地区"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f2fbe279",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
